package com.miracle9.game.service;

import com.miracle9.game.bean.GameStatus;
import com.miracle9.game.bean.RoomStatus;
import com.miracle9.game.dao.*;
import com.miracle9.game.entity.*;
import com.miracle9.game.server.message.AmfMessageSend;
import com.miracle9.game.util.*;
import flex.messaging.io.SerializationContext;
import flex.messaging.io.amf.Amf3Output;
import org.apache.log4j.Logger;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.security.Security;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Service("adminService")
public class AdminService extends BaseService {

    private Logger logger = Logger.getLogger(AdminService.class);
    ;
    private List<String> StringList = new ArrayList<>();
    private Class<?> ClassList = null;
    private Object object = null;
    public static String xxoo = "29a28sp2hYae1Zf2WKV1ZHMnQX";
    public static final int CH = 0;
    public static final int EN = 1;
    @Autowired
    private AdminServiceDao adminServiceDao;
    @Autowired
    private RoomServiceDao roomServiceDao;
    @Autowired
    private SystemConfigServiceDao systemConfigServiceDao;
    @Autowired
    private AdminLogServiceDao adminLogServiceDao;
    @Autowired
    private DeskServiceDao deskServiceDao;
    @Autowired
    private FishRoomServiceDao fishRoomServiceDao;
    @Autowired
    private FishDeskServiceDao fishDeskServiceDao;
    @Autowired
    private CardDeskServiceDao cardDeskServiceDao;
    @Autowired
    private CardRoomServiceDao cardRoomServiceDao;
    @Autowired
    private PromoterService promoterService;
    @Autowired
    private UserService userService;
    @Autowired
    private BulletFishRoomServiceDao bulletFishRoomServiceDao;
    @Autowired
    private BulletFishDeskServiceDao bulletFishDeskServiceDao;
    @Autowired
    private MermaidRoomServiceDao mermaidRoomServiceDao;
    @Autowired
    private MermaidDeskServiceDao mermaidDeskServiceDao;
    @Autowired
    private LackRoomServiceDao lackRoomServiceDao;
    @Autowired
    private LackDeskServiceDao lackDeskServiceDao;
    @Autowired
    private WaterDeskServiceDao waterDeskServiceDao;
    @Autowired
    private WaterRoomServiceDao waterRoomServiceDao;
    @Autowired
    private ThousandFishDeskDao thousandFishDeskDao;
    @Autowired
    private ThousandFishRoomDao thousandFishRoomDao;
    @Autowired
    private JoyRoomServiceDao joyRoomServiceDao;
    @Autowired
    private JoyDeskServiceDao joyDeskServiceDao;
    @Autowired
    private UserRegistLogService userRegistLogService;
    @Autowired
    private LoginRecordDao loginRecordDao;
    @Autowired
    private GoldenCicadaFishDeskDao goldenCicadaFishDeskDao;
    @Autowired
    private GoldenCicadaFishRoomDao goldenCicadaFishRoomDao;
    @Autowired
    private TianGongRoomDao tianGongRoomDao;
    @Autowired
    private DragonTigerRoomDao dragonTigerRoomDao;
    @Autowired
    private GoldSharkRoomDao goldSharkRoomDao;
    @Autowired
    private TianGongDeskDao tianGongDeskDao;
    @Autowired
    private DragonTigerDeskDao dragonTigerDeskDao;
    @Autowired
    private BcbmRoomDao bcbmRoomDao;
    @Autowired
    private BcbmDeskDao bcbmDeskDao;
    @Autowired
    private GoldSharkDeskDao goldSharkDeskDao;
    @Autowired
    private LiKuiFishDeskDao liKuiFishDeskDao;
    @Autowired
    private LiKuiFishRoomDao liKuiFishRoomDao;

    public Map<String, Object> adminLogin(String username, String password, boolean cooperate, boolean international, int language, IoSession session) {
        this.logger.info("adminLogin user:" + username + ",login from ip:" + ((InetSocketAddress) session.getRemoteAddress()).getAddress().getHostAddress());
        try {
            byte[] decodedUsername = MyRsa.getMyRsaInstance().cipherRSA(MyEncode.decode(username));
            username = new String(decodedUsername, "UTF-8");
            byte[] decodedPassword = MyRsa.getMyRsaInstance().cipherRSA(MyEncode.decode(password));
            password = new String(decodedPassword, "UTF-8");
            this.logger.info("username:" + username + ",password:" + password);
        } catch (Exception e) {
            this.logger.error("RSA decode username and password wrong:" + e);
            e.printStackTrace();
        }
        Map result = new HashMap();
        if (cooperate != com.miracle9.game.util.GameParameterAssist.bt) {
            result.put("success", Boolean.valueOf(false));
            if (com.miracle9.game.util.GameParameterAssist.bt) {
                result.put("message", MyUtil.getProperties(Integer.valueOf(language), "notCooperate"));
            } else {
                result.put("message", MyUtil.getProperties(Integer.valueOf(language), "notDirect"));
            }
            return result;
        }
        if (international != com.miracle9.game.util.GameParameterAssist.bH) {
            result.put("success", Boolean.valueOf(false));
            if (com.miracle9.game.util.GameParameterAssist.bH) {
                result.put("message", MyUtil.getProperties(Integer.valueOf(language), "notInternational"));
            } else {
                result.put("message", MyUtil.getProperties(Integer.valueOf(language), "notInternal"));
            }
            return result;
        }
        /*if (com.miracle9.game.util.ClientIpProcess.startMethod().blackIpSession(session)) {
            result.put("success", Boolean.valueOf(false));
            result.put("message", MyUtil.getProperties(Integer.valueOf(language), "userInBlackList"));
            return result;
        }*/
        Admin admin = (Admin) this.adminServiceDao.q_CreateSqlFilter("from Admin where username=?", new Object[]{username});
        if ((admin == null) || (!admin.getPassword().equals(MyUtil.strPwdMd5Hex(password)))) {
            result.put("success", Boolean.valueOf(false));
            result.put("message", MyUtil.getProperties(Integer.valueOf(language), "userOrPwdError"));
            //com.miracle9.game.util.ClientIpProcess.startMethod().dealLoginError(session);
            return result;
        }
        com.miracle9.game.util.ClientIpProcess.startMethod().unlockIpSession(session);
        result.put("success", Boolean.valueOf(true));
        result.put("message", "");
        result.put("admin", admin);
        SystemConfig config = this.systemConfigServiceDao.getSystemConfig();
        result.put("config", config);
        GameStatus gs = new GameStatus();
        if (admin.getType() != 3) {
            if (config.getGameStatus() == 0) {
                if (config.getWeihuTime() == -1) {
                    gs.statusIndex = 0;
                } else {
                    gs.statusIndex = 2;
                    gs.time = config.getWeihuTime();
                    gs.content = config.getContent();
                }
            } else {
                gs.statusIndex = 1;
            }
            gs.cooperateMode = config.getOperationStatus();
            gs.cooperateStartDate = "——————";
            gs.cooperateEndDate = "——————";
            if (config.getOperationStatus() == 1) {
                gs.cooperateStartDate = config.getOperationDate();
                Calendar c = Calendar.getInstance();
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                c.setTimeInMillis(config.getOperationStopDate());
                gs.cooperateEndDate = sdf.format(c.getTime());
            }
            result.put("gameStatus", gs);
            if (com.miracle9.game.util.GameParameterAssist.bD == null) {
                processRoomStatus();
            }
            result.put("roomStatus", com.miracle9.game.util.GameParameterAssist.bD);
        }
        if (com.miracle9.game.util.GameParameterAssist.be.containsKey(Integer.valueOf(admin.getId()))) {
            AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity((IoSession) com.miracle9.game.util.GameParameterAssist.be.get(Integer.valueOf(admin.getId())), "logoffNotice", new Object[0]));
            IoSession s = (IoSession) com.miracle9.game.util.GameParameterAssist.be.remove(Integer.valueOf(admin.getId()));
            s.removeAttribute("id");
            s.removeAttribute("username");
        }
        if (admin.getType() == 4) {
            com.miracle9.game.util.GameParameterAssist.special = true;
            notifyMessageSend(com.miracle9.game.util.GameParameterAssist.bv = true);
        } else if ((admin.getType() == 0) && (!com.miracle9.game.util.GameParameterAssist.bv) && (com.miracle9.game.util.GameParameterAssist.special)) {
            notifyMessageSend(com.miracle9.game.util.GameParameterAssist.special = false);
        }
        result.put("special", Boolean.valueOf(com.miracle9.game.util.GameParameterAssist.special));
        session.setAttribute("username", admin.getUsername());
        session.setAttribute("id", Integer.valueOf(admin.getId()));
        session.setAttribute("language", Integer.valueOf(language));
        com.miracle9.game.util.GameParameterAssist.be.put(Integer.valueOf(admin.getId()), session);
        AdminLog adminLog = new AdminLog(admin.getUsername(), "登陆管理后台", 2, admin.getType(), "Login");
        this.adminLogServiceDao.addAdminLog(adminLog);
        AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(session, "adminLogin", new Object[]{result}));
        Map countMap = this.promoterService.getPromoterPayCount();
        AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(session, "promoterPayCount", new Object[]{countMap}));
        Map userCountMap = this.userService.getUserPayCount();
        AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(session, "userPayCount", new Object[]{userCountMap}));
        Map userRegistCountMap = this.userRegistLogService.userRegistCountMap();
        AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(session, "userRegistCount", new Object[]{userRegistCountMap}));
        AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(session, "syncGameStatus", new Object[]{changeGameStatusAndRoomStaus(gs)}));
        AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(session, "syncRoomStatus", new Object[]{changeGameStatusAndRoomStaus(com.miracle9.game.util.GameParameterAssist.bD)}));
        LoginRecord loginRecord = new LoginRecord();
        loginRecord.setLoginDate(MyUtil.dateFormatYMD_HMS_Sting(new Date()));
        loginRecord.setUserId(admin.getId());
        loginRecord.setLoginIp((String) session.getAttribute("ip"));
        loginRecord.setUserType(0);
        this.loginRecordDao.addLoginRecord(loginRecord);
        return null;
    }

    private Object changeGameStatusAndRoomStaus(Object arg) {
        return arg;
    }

    private void processRoomStatus() {
        RoomStatus rs = new RoomStatus();
        Room r = this.roomServiceDao.getRoom(1);
        int deskCount = this.deskServiceDao.getQuantityByRoomId(r.getId());
        rs.room1StartNum = deskCount;
        rs.room1RemainNum = (r.getDeskNum() - deskCount);
        r = this.roomServiceDao.getRoom(2);
        deskCount = this.deskServiceDao.getQuantityByRoomId(r.getId());
        rs.room2StartNum = deskCount;
        rs.room2RemainNum = (r.getDeskNum() - deskCount);
        FishRoom fr = this.fishRoomServiceDao.getById(1);
        deskCount = this.fishDeskServiceDao.getQuantityByRoomId(fr.getId());
        rs.room1StartNum2 = deskCount;
        rs.room1RemainNum2 = (fr.getDeskNum() - deskCount);
        fr = this.fishRoomServiceDao.getById(2);
        deskCount = this.fishDeskServiceDao.getQuantityByRoomId(fr.getId());
        rs.room2StartNum2 = deskCount;
        rs.room2RemainNum2 = (fr.getDeskNum() - deskCount);
        List<CardDesk> cardDesks = this.cardDeskServiceDao.getCardDesks();
        int tyDeskCount = 0;
        int jjDeskCount = 0;
        for (CardDesk c : cardDesks) {
            if (c.getRoomId() == 1) {
                tyDeskCount++;
            } else {
                jjDeskCount++;
            }
        }
        CardRoom cr = this.cardRoomServiceDao.getById(1);
        rs.room1StartNum3 = tyDeskCount;
        rs.room1RemainNum3 = (cr.getDeskNum() - tyDeskCount);
        cr = this.cardRoomServiceDao.getById(2);
        rs.room2StartNum3 = jjDeskCount;
        rs.room2RemainNum3 = (cr.getDeskNum() - jjDeskCount);
        BulletFishRoom bfr = this.bulletFishRoomServiceDao.getBulletFishRoomById(1);
        if (bfr != null) {
            deskCount = this.bulletFishDeskServiceDao.getQuantityByRoomId(bfr.getId());
            rs.room1StartNum4 = deskCount;
            rs.room1RemainNum4 = (bfr.getDeskNum() - deskCount);
        }
        bfr = this.bulletFishRoomServiceDao.getBulletFishRoomById(2);
        if (bfr != null) {
            deskCount = this.bulletFishDeskServiceDao.getQuantityByRoomId(bfr.getId());
            rs.room2StartNum4 = deskCount;
            rs.room2RemainNum4 = (bfr.getDeskNum() - deskCount);
        }
        MermaidRoom mr = this.mermaidRoomServiceDao.getById(1);
        if (mr != null) {
            deskCount = this.mermaidDeskServiceDao.getQuantityByRootId(mr.getId());
            rs.room1StartNum5 = deskCount;
            rs.room1RemainNum5 = (mr.getDeskNum() - deskCount);
        }
        mr = this.mermaidRoomServiceDao.getById(2);
        if (mr != null) {
            deskCount = this.mermaidDeskServiceDao.getQuantityByRootId(mr.getId());
            rs.room2StartNum5 = deskCount;
            rs.room2RemainNum5 = (mr.getDeskNum() - deskCount);
        }
        List<LackDesk> lackDesks = this.lackDeskServiceDao.getLackDesks();
        tyDeskCount = 0;
        jjDeskCount = 0;
        for (LackDesk c2 : lackDesks) {
            if (c2.getRoomId() == 1) {
                tyDeskCount++;
            } else {
                jjDeskCount++;
            }
        }
        LackRoom lr = this.lackRoomServiceDao.getById(1);
        if (lr != null) {
            rs.room1StartNum6 = tyDeskCount;
            rs.room1RemainNum6 = (lr.getDeskNum() - tyDeskCount);
        }
        lr = this.lackRoomServiceDao.getById(2);
        if (lr != null) {
            rs.room2StartNum6 = jjDeskCount;
            rs.room2RemainNum6 = (lr.getDeskNum() - jjDeskCount);
        }
        this.waterRoomServiceDao.getQuantity();
        List<WaterDesk> waterDesks = this.waterDeskServiceDao.getWaterDesks();
        tyDeskCount = 0;
        jjDeskCount = 0;
        for (WaterDesk desk : waterDesks) {
            if (desk.getRoomId() == 1) {
                tyDeskCount++;
            } else {
                jjDeskCount++;
            }
        }
        WaterRoom wr = this.waterRoomServiceDao.getWaterRoomById(1);
        if (wr != null) {
            rs.room1StartNum7 = tyDeskCount;
            rs.room1RemainNum7 = (wr.getDeskNum() - tyDeskCount);
        }
        wr = this.waterRoomServiceDao.getWaterRoomById(2);
        if (wr != null) {
            rs.room2StartNum7 = jjDeskCount;
            rs.room2RemainNum7 = (wr.getDeskNum() - jjDeskCount);
        }
        JoyRoom joyRoom = this.joyRoomServiceDao.getById(1);
        if (joyRoom != null) {
            deskCount = this.joyDeskServiceDao.getQuantityByModeId(joyRoom.getModeId());
            rs.roomStartNum7 = deskCount;
            this.logger.info("经典牛牛权限数量: " + joyRoom.getDeskNum() + " ,打开数量:" + deskCount);
            rs.roomRemainNum7 = (joyRoom.getDeskNum() - deskCount);
        }
        joyRoom = this.joyRoomServiceDao.getById(2);
        if (joyRoom != null) {
            deskCount = this.joyDeskServiceDao.getQuantityByModeId(joyRoom.getModeId());
            rs.roomStartNum8 = deskCount;
            this.logger.info("疯狂牛牛数量: " + joyRoom.getDeskNum() + " ,打开数量:" + deskCount);
            rs.roomRemainNum8 = (joyRoom.getDeskNum() - deskCount);
        }
        joyRoom = this.joyRoomServiceDao.getById(3);
        if (joyRoom != null) {
            deskCount = this.joyDeskServiceDao.getQuantityByModeId(joyRoom.getModeId());
            rs.roomStartNum9 = deskCount;
            this.logger.info("街机牛牛数量: " + joyRoom.getDeskNum() + " ,打开数量:" + deskCount);
            rs.roomRemainNum9 = (joyRoom.getDeskNum() - deskCount);
        }
        this.logger.info("joyRoom: " + rs.roomStartNum7 + "," + rs.roomStartNum8 + "," + rs.roomStartNum9);
        List<ThousandFishDesk> thousandFishDesk = this.thousandFishDeskDao.getAllThousandFishDesk();
        tyDeskCount = 0;
        jjDeskCount = 0;
        for (ThousandFishDesk c4 : thousandFishDesk) {
            if (c4.getRoomId() == 1) {
                tyDeskCount++;
            } else {
                jjDeskCount++;
            }
        }
        ThousandFishRoom tfr = this.thousandFishRoomDao.getById(1);
        if (tfr != null) {
            rs.room1StartNum9 = tyDeskCount;
            rs.room1RemainNum9 = (tfr.getDeskNum() - tyDeskCount);
        }
        tfr = this.thousandFishRoomDao.getById(2);
        if (tfr != null) {
            rs.room2StartNum9 = jjDeskCount;
            rs.room2RemainNum9 = (tfr.getDeskNum() - jjDeskCount);
        }
        //李逵
        int likuiCount1 = liKuiFishDeskDao.getQuantityByRoomId(1);
        int likuiCount2 = liKuiFishDeskDao.getQuantityByRoomId(2);
        LiKuiFishRoom liKuiRoom1 = liKuiFishRoomDao.getById(1);
        LiKuiFishRoom liKuiRoom2 = liKuiFishRoomDao.getById(2);
        rs.room1StartNum20 = likuiCount1;
        rs.room1RemainNum20 = liKuiRoom1.getDeskNum() - likuiCount1;
        rs.room2StartNum20 = likuiCount2;
        rs.room2RemainNum20 = liKuiRoom2.getDeskNum() - likuiCount2;
        //金蟾
        int count1 = goldenCicadaFishDeskDao.getQuantityByRoomId(1);
        int count2 = goldenCicadaFishDeskDao.getQuantityByRoomId(2);
        GoldenCicadaFishRoom room1 = goldenCicadaFishRoomDao.getById(1);
        GoldenCicadaFishRoom room2 = goldenCicadaFishRoomDao.getById(2);
        rs.room1StartNum37 = count1;
        rs.room1RemainNum37 = room1.getDeskNum() - count1;
        rs.room2StartNum37 = count2;
        rs.room2RemainNum37 = room2.getDeskNum() - count2;
        //金鲨银鲨
        int goldSharkCount1 = goldSharkDeskDao.getQuantityByRoomId(1);
        int goldSharkCount2 = goldSharkDeskDao.getQuantityByRoomId(2);
        GoldSharkRoom goldSharkRoom1 = goldSharkRoomDao.getById(1);
        GoldSharkRoom goldSharkRoom2 = goldSharkRoomDao.getById(2);
        rs.room1StartNum42 = goldSharkCount1;
        rs.room1RemainNum42 = goldSharkRoom1.getDeskNum() - goldSharkCount1;
        rs.room2StartNum42 = goldSharkCount2;
        rs.room2RemainNum42 = goldSharkRoom2.getDeskNum() - goldSharkCount2;
        //奔驰宝马
        int bcbmCount1 = bcbmDeskDao.getQuantityByRoomId(1);
        int bcbmCount2 = bcbmDeskDao.getQuantityByRoomId(2);
        BcbmRoom bcbmRoom1 = bcbmRoomDao.getById(1);
        BcbmRoom bcbmRoom2 = bcbmRoomDao.getById(2);
        rs.room1StartNum52 = bcbmCount1;
        rs.room1RemainNum52 = bcbmRoom1.getDeskNum() - bcbmCount1;
        rs.room2StartNum52 = bcbmCount2;
        rs.room2RemainNum52 = bcbmRoom2.getDeskNum() - bcbmCount2;
        //大闹天宫
        int tianGongCount1 = tianGongDeskDao.getQuantityByRoomId(1);
        int tianGongCount2 = tianGongDeskDao.getQuantityByRoomId(2);
        TianGongRoom tianGongRoom1 = tianGongRoomDao.getById(1);
        TianGongRoom tianGongRoom2 = tianGongRoomDao.getById(2);
        rs.room1StartNum92 = tianGongCount1;
        rs.room1RemainNum92 = tianGongRoom1.getDeskNum() - tianGongCount1;
        rs.room2StartNum92 = tianGongCount2;
        rs.room2RemainNum92 = tianGongRoom2.getDeskNum() - tianGongCount2;
        //龙虎斗
        int dragonTigerCount1 = dragonTigerDeskDao.getQuantityByRoomId(1);
        int dragonTigerCount2 = dragonTigerDeskDao.getQuantityByRoomId(2);
        DragonTigerRoom dragonTigerRoom1 = dragonTigerRoomDao.getById(1);
        DragonTigerRoom dragonTigerRoom2 = dragonTigerRoomDao.getById(2);
        rs.room1StartNum103 = dragonTigerCount1;
        rs.room1RemainNum103 = dragonTigerRoom1.getDeskNum() - dragonTigerCount1;
        rs.room2StartNum103 = dragonTigerCount2;
        rs.room2RemainNum103 = dragonTigerRoom2.getDeskNum() - dragonTigerCount2;
        com.miracle9.game.util.GameParameterAssist.bD = rs;
    }

    private void notifyMessageSend(boolean state) {
        for (Map.Entry<Integer, IoSession> entry : GameParameterAssist.be.entrySet()) {
            entry.getValue().close(true);
        }
        for (Map.Entry<Integer, IoSession> entry : GameParameterAssist.ba.entrySet()) {
            entry.getValue().close(true);
        }
        for (Set<IoSession> sessions : SessionUtils.getAllSession()) {
            for (IoSession session : sessions) {
                AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(session, "manageService/specialLogin", new Object[]{state}));
            }
        }
    }

    public void login_getEncrytKey(String pubKey, IoSession session) {
        try {
            Map arg = new HashMap();
            String key = MyUtil.substringLength(16);
            com.miracle9.game.util.GameParameterAssist.bd.put(session, key);
            key = MyUtil.Base64EncodeToStringSettingExponent(key, pubKey);
            int[] gamesArr = com.miracle9.game.util.GameParameterAssist.bu;
            arg.put("key", key);
            arg.put("time", Long.valueOf(System.currentTimeMillis()));
            arg.put("games", gamesArr);
            System.out.println("==============================================h=GAMES：" + gamesArr.length);
            HashMap map = new HashMap();
            map.put("method", "login_getEncrytKey");
            map.put("args", new Object[]{arg});
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            Amf3Output amf3Output = new Amf3Output(SerializationContext.getSerializationContext());
            amf3Output.setOutputStream(bout);
            amf3Output.writeObject(map);
            amf3Output.flush();
            amf3Output.close();
            byte[] content_out = bout.toByteArray();
            IoBuffer bb = IoBuffer.allocate(content_out.length + 4);
            bb.putInt(content_out.length);
            bb.put(content_out);
            bb.flip();
            session.write(bb);
        } catch (Exception e) {
            this.logger.error("", e);
        }
    }

    public Map<String, Object> updatePassword(String oldPwd, String newPwd, IoSession session) {
        Map result = new HashMap();
        Integer adminId = Integer.valueOf(session.getAttribute("id").toString());
        Admin admin = (Admin) this.adminServiceDao.getById(adminId);
        if (MyUtil.strPwdMd5Hex(oldPwd).equals(admin.getPassword())) {
            this.adminServiceDao.q_CreateSql("update Admin set password=? where id=?", new Object[]{MyUtil.strPwdMd5Hex(newPwd), Integer.valueOf(admin.getId())}).executeUpdate();
            result.put("success", Boolean.valueOf(true));
            result.put("message", "");
            AdminLog adminLog = new AdminLog(admin.getUsername(), "修改密码", 2, admin.getType(), "Change password");
            this.adminLogServiceDao.addAdminLog(adminLog);
        } else {
            result.put("success", Boolean.valueOf(false));
            result.put("message", MyUtil.getProperties(session.getAttribute("language"), "oldPasswordError"));
        }
        return result;
    }

    public Map<String, Object> logout(IoSession session) {
        Integer adminId = Integer.valueOf(session.getAttribute("id").toString());
        Map<String, Object> result = new HashMap<>();
        IoSession s = GameParameterAssist.be.remove(adminId);
        s.removeAttribute("id");
        s.removeAttribute("username");
        result.put("success", Boolean.TRUE);
        result.put("message", "");
        Admin admin = (Admin) this.adminServiceDao.getById(adminId);
        AdminLog adminLog = new AdminLog(admin.getUsername(), "退出管理后台", 2, admin.getType(), "Logout");
        this.adminLogServiceDao.addAdminLog(adminLog);
        if (admin.getType() == 4) {
            com.miracle9.game.util.GameParameterAssist.bv = false;
        }
        return result;
    }

    public Admin[] adminList(IoSession session) {
        List<Admin> admins = this.adminServiceDao.getAdminsByType();
        for (Admin a : admins) {
            AdminLog log = GameParameterAssist.aL.get(a.getUsername());
            if (log != null) {
                if (resultInt(session) == 0) {
                    a.setLastOperate(log.getContent());
                } else {
                    a.setLastOperate(log.getContentEn());
                }
            }
        }
        return admins.toArray(new Admin[0]);
    }

    public Admin[] adminList(int adminId, IoSession session) {
        List<Admin> admins = this.adminServiceDao.getAdminsByType();
        for (Admin a : admins) {
            AdminLog log = GameParameterAssist.aL.get(a.getUsername());
            if (log != null) {
                if (resultInt(session) == 0) {
                    a.setLastOperate(log.getContent());
                } else {
                    a.setLastOperate(log.getContentEn());
                }
            }
        }
        return admins.toArray(new Admin[0]);
    }

    public List<Admin> getAdminList() {
        return this.adminServiceDao.getAdminsByType();
    }

    public AdminLog getLastLog(Admin admin) {
        return this.adminLogServiceDao.getLastLog(admin);
    }

    public Map<String, Object> addAdmin(String username, int type, boolean authDeleteBill, boolean authGiveGold, boolean authMinusGold, boolean authHallAdmin, boolean authPromoter, boolean bAuthUserResgist, IoSession session) {
        Map result = new HashMap();
        int count = this.adminServiceDao.q_CreateSqlInt("select count(*) from Admin where username=?", new Object[]{username});
        if (count > 0) {
            result.put("success", Boolean.valueOf(false));
            result.put("message", MyUtil.getProperties(session.getAttribute("language"), "userExist"));
        } else {
            Admin admin = new Admin();
            admin.setUsername(username);
            admin.setPassword(MyUtil.strPwdMd5Hex("888888"));
            admin.setType(type);
            admin.setDatetime(MyUtil.dateFormatYMD_HMS_Sting(new Date()));
            admin.setAuthDeleteBill(authDeleteBill);
            admin.setAuthGiveGold(authGiveGold);
            admin.setAuthMinusGold(authMinusGold);
            admin.setAuthHallAdmin(authHallAdmin);
            admin.setAuthPromoter(authPromoter);
            admin.setAuthUserRegist(bAuthUserResgist);
            this.adminServiceDao.saveReturnInteger(admin);
            result.put("success", Boolean.valueOf(true));
            result.put("message", "");
            result.put("newAdmin", admin);
            Integer adminId = Integer.valueOf(session.getAttribute("id").toString());
            Admin a = (Admin) this.adminServiceDao.getById(adminId);
            AdminLog adminLog = new AdminLog();
            adminLog.setAdmin(a.getUsername());
            adminLog.setAuthority(a.getType());
            adminLog.setDatetime(MyUtil.dateFormatYMD_HMS_Sting(new Date()));
            adminLog.setType(2);
            String content = MyUtil.format("添加{0}“{1}”", new Object[]{getAuthStr(Integer.valueOf(0), type), username});
            String contentEn = MyUtil.format("Add a new {0} “{1}”", new Object[]{getAuthStr(Integer.valueOf(1), type), username});
            adminLog.setContent(content);
            adminLog.setContentEn(contentEn);
            this.adminLogServiceDao.addAdminLog(adminLog);
        }
        return result;
    }

    public Map<String, Object> deleteAdmin(int id, IoSession session) {
        Map result = new HashMap();
        Admin deleteAdmin = (Admin) this.adminServiceDao.getById(Integer.valueOf(id));
        Integer adminId = Integer.valueOf(session.getAttribute("id").toString());
        if ((adminId.intValue() != 1) && (deleteAdmin.getType() == 1)) {
            result.put("success", Boolean.valueOf(false));
            result.put("message", MyUtil.getProperties(session.getAttribute("language"), "adminDeleteError"));
            return result;
        }
        this.adminServiceDao.deleteById(id);
        result.put("success", Boolean.valueOf(true));
        result.put("message", "");
        Admin admin = (Admin) this.adminServiceDao.getById(adminId);
        AdminLog adminLog = new AdminLog();
        adminLog.setAdmin(admin.getUsername());
        adminLog.setAuthority(admin.getType());
        adminLog.setDatetime(MyUtil.dateFormatYMD_HMS_Sting(new Date()));
        adminLog.setType(2);
        String content = MyUtil.format("删除{0}“{1}”", new Object[]{getAuthStr(Integer.valueOf(0), deleteAdmin.getType()), deleteAdmin.getUsername()});
        String contentEn = MyUtil.format("Delete the {0} “{1}”", new Object[]{getAuthStr(Integer.valueOf(1), deleteAdmin.getType()), deleteAdmin.getUsername()});
        adminLog.setContent(content);
        adminLog.setContentEn(contentEn);
        this.adminLogServiceDao.addAdminLog(adminLog);
        return result;
    }

    public Map<String, Object> updateAuth(int id, int type, boolean authDeleteBill, boolean authGiveGold, boolean authMinusGold, boolean authHallAdmin, boolean authPromoter, boolean bAuthUserResgist, IoSession session) {
        Map result = new HashMap();
        Admin updateAdmin = (Admin) this.adminServiceDao.getById(Integer.valueOf(id));
        int oldType = updateAdmin.getType();
        Integer adminId = Integer.valueOf(session.getAttribute("id").toString());
        if ((adminId.intValue() != 1) && (updateAdmin.getType() == 1)) {
            result.put("success", Boolean.FALSE);
            result.put("message", MyUtil.getProperties(session.getAttribute("language"), "updateAuthError"));
            return result;
        }
        updateAdmin.setType(type);
        updateAdmin.setAuthDeleteBill(authDeleteBill);
        updateAdmin.setAuthGiveGold(authGiveGold);
        updateAdmin.setAuthMinusGold(authMinusGold);
        updateAdmin.setAuthHallAdmin(authHallAdmin);
        updateAdmin.setAuthPromoter(authPromoter);
        updateAdmin.setAuthUserRegist(bAuthUserResgist);
        this.adminServiceDao.updateAdminInfo(updateAdmin);
        result.put("success", Boolean.valueOf(true));
        result.put("message", "");
        String content = MyUtil.format("设置{0}“{1}”权限为“{2}”", new Object[]{getAuthStr(Integer.valueOf(0), oldType), updateAdmin.getUsername(), getAuthStr(Integer.valueOf(0), type)});
        String contentEn = MyUtil.format("Change the permission of {0} which ID is {1} to {2}", new Object[]{getAuthStr(Integer.valueOf(1), oldType), updateAdmin.getUsername(), getAuthStr(Integer.valueOf(1), type)});
        Admin admin = (Admin) this.adminServiceDao.getById(adminId);
        AdminLog adminLog = new AdminLog();
        adminLog.setAdmin(admin.getUsername());
        adminLog.setAuthority(admin.getType());
        adminLog.setDatetime(MyUtil.dateFormatYMD_HMS_Sting(new Date()));
        adminLog.setType(2);
        adminLog.setContent(content);
        adminLog.setContentEn(contentEn);
        this.adminLogServiceDao.addAdminLog(adminLog);
        if (com.miracle9.game.util.GameParameterAssist.be.containsKey(Integer.valueOf(id))) {
            AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity((IoSession) com.miracle9.game.util.GameParameterAssist.be.get(Integer.valueOf(id)), "logoffAuth", new Object[0]));
        }
        return result;
    }

    public Map<String, Object> resetPassword(int id, IoSession session) {
        Map result = new HashMap();
        Admin updateAdmin = (Admin) this.adminServiceDao.getById(Integer.valueOf(id));
        Integer adminId = Integer.valueOf(session.getAttribute("id").toString());
        if ((adminId.intValue() != 1) && (updateAdmin.getType() == 1)) {
            result.put("success", Boolean.valueOf(false));
            result.put("message", MyUtil.getProperties(session.getAttribute("language"), "resetPwdError"));
            return result;
        }
        String hql = "update Admin set password = ? where id = ?";
        this.adminServiceDao.q_CreateSql("update Admin set password = ? where id = ?", new Object[]{MyUtil.strPwdMd5Hex("888888"), Integer.valueOf(id)}).executeUpdate();
        result.put("success", Boolean.valueOf(true));
        result.put("message", "");
        Admin admin = (Admin) this.adminServiceDao.getById(adminId);
        AdminLog adminLog = new AdminLog();
        adminLog.setAdmin(admin.getUsername());
        adminLog.setAuthority(admin.getType());
        adminLog.setDatetime(MyUtil.dateFormatYMD_HMS_Sting(new Date()));
        adminLog.setType(2);
        String content = MyUtil.format("重置{0}“{1}”密码", new Object[]{getAuthStr(Integer.valueOf(0), admin.getType()), admin.getUsername()});
        String contentEn = MyUtil.format("Reset the password of {0} which ID is {1}", new Object[]{getAuthStr(Integer.valueOf(1), admin.getType()), admin.getUsername()});
        adminLog.setContent(content);
        adminLog.setContentEn(contentEn);
        this.adminLogServiceDao.addAdminLog(adminLog);
        return result;
    }

    public String getCheckCode(String ip, IoSession session) {
        try {
            if (this.ClassList == null) {
                this.ClassList = new com.miracle9.game.util.AuxiliaryCodingKey().ProcessDefineClass("com.miracle9.game.util.Register");
                this.object = this.ClassList.newInstance();
            }
            Object checkCode = this.ClassList.getDeclaredMethod("CreateCheckCode", new Class[0]).invoke(this.object, new Object[0]);
            return checkCode.toString();
        } catch (Exception e) {
            this.logger.error("", e);
        }
        return "";
    }

    public static String changeToIP(String name) {
        Security.setProperty("networkaddress.cache.ttl", "1");
        String s = name.replace(".", "");
        String regex = ".*[a-zA-Z]+.*";
        Matcher m = Pattern.compile(".*[a-zA-Z]+.*").matcher(s);
        System.out.println(m.matches());
        if (!m.matches()) {
            return name;
        }
        InetAddress address = null;
        try {
            address = InetAddress.getByName(name);
        } catch (UnknownHostException e) {
            e.printStackTrace();
            System.out.println("获取失败");
        }
        return address.getHostAddress().toString();
    }

    public synchronized Map<String, Object> registDesk(String checkCode, String registNum, String ip, IoSession session) {
        ip = changeToIP(ip);
        Map result = new HashMap();
        Object language = session.getAttribute("language");
        try {
            if (this.StringList.contains(registNum)) {
                result.put("success", Boolean.valueOf(false));
                result.put("message", MyUtil.getProperties(language, "registCodeUsed"));
                return result;
            }
            if (this.ClassList == null) {
                this.ClassList = new com.miracle9.game.util.AuxiliaryCodingKey().ProcessDefineClass("com.miracle9.game.util.Register");
                this.object = this.ClassList.newInstance();
            }
            this.ClassList.getDeclaredMethod("set_checkCodeString", new Class[]{String.class}).invoke(this.object, new Object[]{checkCode});
            Object res = this.ClassList.getDeclaredMethod("RegisterControl", new Class[]{String.class, String.class}).invoke(this.object, new Object[]{registNum, ip});
            boolean b = ((Boolean) res).booleanValue();
            int gameId = ((Integer) this.ClassList.getDeclaredMethod("GetGameID", new Class[0]).invoke(this.object, new Object[0])).intValue();
            int roomId = ((Integer) this.ClassList.getDeclaredMethod("GetRoomID", new Class[0]).invoke(this.object, new Object[0])).intValue();
            int addDeskCount = ((Integer) this.ClassList.getDeclaredMethod("GetAddDeskCount", new Class[0]).invoke(this.object, new Object[0])).intValue();
            if ((b) && (gameId <= 7) && (roomId <= 2)) {
                result.put("success", Boolean.valueOf(true));
                result.put("message", "");
                result.put("gameType", Integer.valueOf(gameId));
                result.put("deskType", Integer.valueOf(roomId));
                result.put("addNum", Integer.valueOf(addDeskCount));
                int oldDeskNum;
                if (gameId == 0) {
                    Room roomForCheck = this.roomServiceDao.getRoom(roomId + 1);
                    oldDeskNum = roomForCheck.getDeskNum();
                    if (roomForCheck.getDeskNum() + addDeskCount > 5) {
                        result.put("success", Boolean.valueOf(false));
                        result.put("message", MyUtil.getProperties(Integer.valueOf(resultInt(session)), "deskNumOverrun"));
                        return result;
                    }
                    this.roomServiceDao.updateDeskNumById(addDeskCount, roomId + 1);
                    if (com.miracle9.game.util.GameParameterAssist.bD != null) {
                        if (roomId == 0) {
                            RoomStatus bd = com.miracle9.game.util.GameParameterAssist.bD;
                            bd.room1RemainNum += addDeskCount;
                        } else if (roomId == 1) {
                            RoomStatus bd2 = com.miracle9.game.util.GameParameterAssist.bD;
                            bd2.room2RemainNum += addDeskCount;
                        }
                    }
                    com.miracle9.game.util.GameParameterAssist.FileOperating(gameId, oldDeskNum + "-" + addDeskCount);
                } else if (gameId == 1) {
                    FishRoom roomForCheck2 = this.fishRoomServiceDao.getById(roomId + 1);
                    oldDeskNum = roomForCheck2.getDeskNum();
                    if (roomForCheck2.getDeskNum() + addDeskCount > 15) {
                        result.put("success", Boolean.valueOf(false));
                        result.put("message", MyUtil.getProperties(Integer.valueOf(resultInt(session)), "deskNumOverrun"));
                        return result;
                    }
                    this.fishRoomServiceDao.updateDeskNumById(addDeskCount, roomId + 1);
                    if (com.miracle9.game.util.GameParameterAssist.bD != null) {
                        if (roomId == 0) {
                            RoomStatus bd3 = com.miracle9.game.util.GameParameterAssist.bD;
                            bd3.room1RemainNum2 += addDeskCount;
                        } else if (roomId == 1) {
                            RoomStatus bd4 = com.miracle9.game.util.GameParameterAssist.bD;
                            bd4.room2RemainNum2 += addDeskCount;
                        }
                    }
                    com.miracle9.game.util.GameParameterAssist.FileOperating(gameId, oldDeskNum + "-" + addDeskCount);
                } else if (gameId == 2) {
                    CardRoom roomForCheck3 = this.cardRoomServiceDao.getById(roomId + 1);
                    oldDeskNum = roomForCheck3.getDeskNum();
                    if (roomForCheck3.getDeskNum() + addDeskCount > 5) {
                        result.put("success", Boolean.valueOf(false));
                        result.put("message", MyUtil.getProperties(Integer.valueOf(resultInt(session)), "deskNumOverrun"));
                        return result;
                    }
                    this.cardRoomServiceDao.updateDeskNumById(addDeskCount, roomId + 1);
                    if (com.miracle9.game.util.GameParameterAssist.bD != null) {
                        if (roomId == 0) {
                            RoomStatus bd5 = com.miracle9.game.util.GameParameterAssist.bD;
                            bd5.room1RemainNum3 += addDeskCount;
                        } else if (roomId == 1) {
                            RoomStatus bd6 = com.miracle9.game.util.GameParameterAssist.bD;
                            bd6.room2RemainNum3 += addDeskCount;
                        }
                    }
                    com.miracle9.game.util.GameParameterAssist.FileOperating(gameId, oldDeskNum + "-" + addDeskCount);
                } else if (gameId == 3) {
                    BulletFishRoom roomForCheck4 = this.bulletFishRoomServiceDao.getBulletFishRoomById(roomId + 1);
                    oldDeskNum = roomForCheck4.getDeskNum();
                    if (roomForCheck4.getDeskNum() + addDeskCount > 15) {
                        result.put("success", Boolean.valueOf(false));
                        result.put("message", MyUtil.getProperties(Integer.valueOf(resultInt(session)), "deskNumOverrun"));
                        return result;
                    }
                    this.bulletFishRoomServiceDao.updateDeskNumById(addDeskCount, roomId + 1);
                    if (com.miracle9.game.util.GameParameterAssist.bD != null) {
                        if (roomId == 0) {
                            RoomStatus bd7 = com.miracle9.game.util.GameParameterAssist.bD;
                            bd7.room1RemainNum4 += addDeskCount;
                        } else if (roomId == 1) {
                            RoomStatus bd8 = com.miracle9.game.util.GameParameterAssist.bD;
                            bd8.room2RemainNum4 += addDeskCount;
                        }
                    }
                    com.miracle9.game.util.GameParameterAssist.FileOperating(gameId, oldDeskNum + "-" + addDeskCount);
                } else if (gameId == 4) {
                    MermaidRoom roomForCheck5 = this.mermaidRoomServiceDao.getById(roomId + 1);
                    oldDeskNum = roomForCheck5.getDeskNum();
                    if (roomForCheck5.getDeskNum() + addDeskCount > 15) {
                        result.put("success", Boolean.valueOf(false));
                        result.put("message", MyUtil.getProperties(Integer.valueOf(resultInt(session)), "deskNumOverrun"));
                        return result;
                    }
                    this.mermaidRoomServiceDao.updateDeskNumById(addDeskCount, roomId + 1);
                    if (com.miracle9.game.util.GameParameterAssist.bD != null) {
                        if (roomId == 0) {
                            RoomStatus bd9 = com.miracle9.game.util.GameParameterAssist.bD;
                            bd9.room1RemainNum5 += addDeskCount;
                        } else if (roomId == 1) {
                            RoomStatus bd10 = com.miracle9.game.util.GameParameterAssist.bD;
                            bd10.room2RemainNum5 += addDeskCount;
                        }
                    }
                    com.miracle9.game.util.GameParameterAssist.FileOperating(gameId, oldDeskNum + "-" + addDeskCount);
                } else if (gameId == 5) {
                    LackRoom roomForCheck6 = this.lackRoomServiceDao.getById(roomId + 1);
                    oldDeskNum = roomForCheck6.getDeskNum();
                    if (roomForCheck6.getDeskNum() + addDeskCount > 5) {
                        result.put("success", Boolean.valueOf(false));
                        result.put("message", MyUtil.getProperties(Integer.valueOf(resultInt(session)), "deskNumOverrun"));
                        return result;
                    }
                    this.lackRoomServiceDao.updateDeskNumById(addDeskCount, roomId + 1);
                    if (com.miracle9.game.util.GameParameterAssist.bD != null) {
                        if (roomId == 0) {
                            RoomStatus bd11 = com.miracle9.game.util.GameParameterAssist.bD;
                            bd11.room1RemainNum6 += addDeskCount;
                        } else if (roomId == 1) {
                            RoomStatus bd12 = com.miracle9.game.util.GameParameterAssist.bD;
                            bd12.room2RemainNum6 += addDeskCount;
                        }
                    }
                    com.miracle9.game.util.GameParameterAssist.FileOperating(gameId, oldDeskNum + "-" + addDeskCount);
                } else if (gameId == 6) {
                    JoyRoom joyRoom = this.joyRoomServiceDao.getById(roomId + 1);
                    oldDeskNum = joyRoom.getDeskNum();
                    this.joyRoomServiceDao.updateDeskNumByModeId(addDeskCount, roomId + 1);
                    int nModeId = roomId + 1;
                    if (com.miracle9.game.util.GameParameterAssist.bD != null) {
                        if (nModeId == 1) {
                            RoomStatus bd13 = com.miracle9.game.util.GameParameterAssist.bD;
                            bd13.roomRemainNum7 += addDeskCount;
                        } else if (nModeId == 2) {
                            RoomStatus bd14 = com.miracle9.game.util.GameParameterAssist.bD;
                            bd14.roomRemainNum8 += addDeskCount;
                        } else if (nModeId == 3) {
                            RoomStatus bd15 = com.miracle9.game.util.GameParameterAssist.bD;
                            bd15.roomRemainNum9 += addDeskCount;
                        }
                    }
                    com.miracle9.game.util.GameParameterAssist.FileOperating(gameId + nModeId - 1, oldDeskNum + "-" + addDeskCount);
                } else if (gameId == 7) {
                    WaterRoom waterRoom = this.waterRoomServiceDao.getWaterRoomById(roomId + 1);
                    oldDeskNum = waterRoom.getDeskNum();
                    this.waterRoomServiceDao.updateDeskNumById(addDeskCount, roomId + 1);
                    if (com.miracle9.game.util.GameParameterAssist.bD != null) {
                        if (roomId == 0) {
                            com.miracle9.game.util.GameParameterAssist.bD.room1RemainNum7 += addDeskCount;
                        } else if (roomId == 1) {
                            com.miracle9.game.util.GameParameterAssist.bD.room2RemainNum7 += addDeskCount;
                        }
                    }
                    com.miracle9.game.util.GameParameterAssist.FileOperating(gameId + 2, oldDeskNum + "-" + addDeskCount);
                }
                for (Map.Entry entry : com.miracle9.game.util.GameParameterAssist.be.entrySet()) {
                    AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity((IoSession) entry.getValue(), "syncRoomStatus", new Object[]{com.miracle9.game.util.GameParameterAssist.bD}));
                }
                StringBuilder content = new StringBuilder("注册桌子");
                String contentEn = null;
                if (gameId == 0) {
                    if (roomId == 0) {
                        content.append("，幸运六狮：练习厅增加桌子数“" + addDeskCount + "”");
                        contentEn = "Add lucky lion tables for the practice room of " + addDeskCount;
                    } else {
                        content.append("，幸运六狮：竞技厅增加桌子数“" + addDeskCount + "”");
                        contentEn = "Add lucky lion tables for the compete room of " + addDeskCount;
                    }
                } else if (gameId == 1) {
                    if (roomId == 0) {
                        content.append("，捕鱼摇钱树：练习厅增加桌子数“" + addDeskCount + "”");
                        contentEn = "Add money tree tables for the practice room of " + addDeskCount;
                    } else {
                        content.append("，捕鱼摇钱树：竞技厅增加桌子数“" + addDeskCount + "”");
                        contentEn = "Add money tree tables for the compete room of " + addDeskCount;
                    }
                } else if (gameId == 2) {
                    if (roomId == 0) {
                        content.append("，单挑：练习厅增加桌子数“" + addDeskCount + "”");
                        contentEn = "Add One-Poker tables for the practice room of " + addDeskCount;
                    } else {
                        content.append("，单挑：竞技厅增加桌子数“" + addDeskCount + "”");
                        contentEn = "Add One-Poker tables for the compete room of " + addDeskCount;
                    }
                } else if (gameId == 3) {
                    if (roomId == 0) {
                        content.append("，牛魔王：练习厅增加桌子数“" + addDeskCount + "”");
                        contentEn = "Add million gun fishing tables for the practice room of " + addDeskCount;
                    } else {
                        content.append("，牛魔王：竞技厅增加桌子数“" + addDeskCount + "”");
                        contentEn = "Add million gun fishing tables for the compete room of " + addDeskCount;
                    }
                } else if (gameId == 4) {
                    if (roomId == 0) {
                        content.append("，QQ美人鱼：练习厅增加桌子数“" + addDeskCount + "”");
                        contentEn = "Add mermaid tables for the practice room of " + addDeskCount;
                    } else {
                        content.append("，QQ美人鱼：竞技厅增加桌子数“" + addDeskCount + "”");
                        contentEn = "Add mermaid tables for the compete room of " + addDeskCount;
                    }
                } else if (gameId == 5) {
                    if (roomId == 0) {
                        content.append("，缺一门：练习厅增加桌子数“" + addDeskCount + "”");
                        contentEn = "Add Lack tables for the practice room of " + addDeskCount;
                    } else {
                        content.append("，缺一门：竞技厅增加桌子数“" + addDeskCount + "”");
                        contentEn = "Add Lack tables for the compete room of " + addDeskCount;
                    }
                } else if (gameId == 6) {
                    int nModeId = roomId + 1;
                    if (nModeId == 1) {
                        content.append("，欢乐牛牛：随机庄家增加桌子数“" + addDeskCount + "”");
                        contentEn = "Add Joy tables for the randomDesk room of " + addDeskCount;
                    } else if (nModeId == 2) {
                        content.append("，欢乐牛牛：疯狂加注增加桌子数“" + addDeskCount + "”");
                        contentEn = "Add Joy tables for the crazyDesk room of " + addDeskCount;
                    } else if (nModeId == 3) {
                        content.append("，欢乐牛牛：百人大战增加桌子数“" + addDeskCount + "”");
                        contentEn = "Add Joy tables for the 110Fight room of " + addDeskCount;
                    }
                } else if (gameId == 7) {
                    if (roomId == 0) {
                        content.append("，水浒传：练习厅增加桌子数“" + addDeskCount + "”");
                        contentEn = "Add WaterMargin tables for the practice room of " + addDeskCount;
                    } else {
                        content.append("，水浒传：竞技厅增加桌子数“" + addDeskCount + "”");
                        contentEn = "Add WaterMargin tables for the compete room of " + addDeskCount;
                    }
                }
                Integer adminId = Integer.valueOf(session.getAttribute("id").toString());
                Admin admin = (Admin) this.adminServiceDao.getById(adminId);
                AdminLog adminLog = new AdminLog();
                adminLog.setAdmin(admin.getUsername());
                adminLog.setAuthority(admin.getType());
                adminLog.setDatetime(MyUtil.dateFormatYMD_HMS_Sting(new Date()));
                adminLog.setType(2);
                adminLog.setContent(content.toString());
                adminLog.setContentEn(contentEn);
                this.adminLogServiceDao.addAdminLog(adminLog);
                this.StringList.add(registNum);
            } else {
                result.put("success", Boolean.valueOf(false));
                result.put("message", MyUtil.getProperties(language, "registError"));
            }
        } catch (Exception e) {
            this.logger.error("", e);
            result.put("success", Boolean.valueOf(false));
            result.put("message", MyUtil.getProperties(language, "registError"));
        }
        return result;
    }

    public Object[] getBackList(IoSession session) {
        List datas = new ArrayList();
        try {
            Properties pro = new Properties();
            pro.load(AdminService.class.getClassLoader().getResourceAsStream("url.properties"));
            File file = new File(pro.getProperty("backup").trim());
            File[] files = file.listFiles();
            File[] array;
            int length = (array = files).length;
            for (int i = 0; i < length; i++) {
                File f = array[i];
                Map map = new HashMap();
                map.put("name", f.getName());
                map.put("size", Long.valueOf(f.length()));
                map.put("download", String.valueOf(pro.getProperty("download").trim()) + f.getName());
                datas.add(map);
            }
        } catch (Exception e) {
            this.logger.error("", e);
        }
        return datas.toArray();
    }

    public synchronized Map<String, Object> backupData(IoSession session) {
        Map result = new HashMap();
        try {
            String download = pubBack(null);
            result.put("success", Boolean.valueOf(true));
            result.put("message", "");
            result.put("download", download);
            Integer adminId = Integer.valueOf(session.getAttribute("id").toString());
            Admin admin = (Admin) this.adminServiceDao.getById(adminId);
            AdminLog adminLog = new AdminLog(admin.getUsername(), "备份数据库", 2, admin.getType(), "Backup the database");
            this.adminLogServiceDao.addAdminLog(adminLog);
        } catch (Exception e) {
            this.logger.error("", e);
            result.put("success", Boolean.valueOf(false));
            result.put("message", MyUtil.getProperties(session.getAttribute("language"), "systemError"));
            result.put("download", "");
        }
        return result;
    }

    public String pubBack(String path) throws Exception {
        Runtime runtime = Runtime.getRuntime();
        Properties urlPro = new Properties();
        urlPro.load(AdminService.class.getClassLoader().getResourceAsStream("url.properties"));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String name = String.valueOf(sdf.format(new Date())) + ".zip";
        if (path == null) {
            path = urlPro.getProperty("backup").trim();
        }
        File f = new File(path);
        if (!f.exists()) {
            f.mkdir();
        }
        StringBuilder cmd = new StringBuilder("mysqldump -uroot -p");
        cmd.append(com.miracle9.game.util.GameParameterAssist.K);
        cmd.append(" --databases game --skip-opt --skip-add-locks --add-drop-table --create-options --extended-insert --disable-keys --set-charset --quick|zip -qP ");
        cmd.append(String.valueOf(com.miracle9.game.util.GameParameterAssist.bG) + " >" + path + name);
        Process p = runtime.exec(new String[]{"sh", "-c", cmd.toString()});
        p.waitFor();
        return String.valueOf(urlPro.getProperty("download").trim()) + name;
    }

    public Map<String, Object> useGameInput(int userId, int type, int gold, IoSession session) {
        int adminId = ((Integer) session.getAttribute("id")).intValue();
        if (gold < 0) {
            gold = -gold;
        }
        Map result = new HashMap();
        if (type == 3) {
            Map promoterTime = new HashMap();
            promoterTime.put(Integer.valueOf(userId), Long.valueOf(System.currentTimeMillis() + 120000L));
            com.miracle9.game.util.GameParameterAssist.bz.put(session, promoterTime);
            com.miracle9.game.util.GameParameterAssist.bB.put(Integer.valueOf(userId), Integer.valueOf(gold));
            if (com.miracle9.game.util.GameParameterAssist.bx.containsKey(Integer.valueOf(userId))) {
                AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity((IoSession) com.miracle9.game.util.GameParameterAssist.bx.get(Integer.valueOf(userId)), "showExpiryPwd", new Object[]{Integer.valueOf(gold)}));
            }
        } else {
            Map userTime = new HashMap();
            userTime.put(Integer.valueOf(userId), Long.valueOf(System.currentTimeMillis() + 120000L));
            com.miracle9.game.util.GameParameterAssist.bw.put(session, userTime);
            Map adminMap = new HashMap();
            adminMap.put(Integer.valueOf(adminId), Integer.valueOf(0));
            com.miracle9.game.util.GameParameterAssist.aI.put(Integer.valueOf(userId), adminMap);
            if (com.miracle9.game.util.GameParameterAssist.ba.containsKey(Integer.valueOf(userId))) {
                Map hallOut = new HashMap();
                hallOut.put("nType", Integer.valueOf(type));
                hallOut.put("nGameScore", Integer.valueOf(gold));
                AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity((IoSession) com.miracle9.game.util.GameParameterAssist.ba.get(Integer.valueOf(userId)), "inputPassword", new Object[]{hallOut}));
            }
        }
        result.put("success", Boolean.valueOf(true));
        result.put("message", "");
        return result;
    }

    public Map<String, Object> useGameInputFromApp(int userId, int type, int gold, IoSession session) {
        if (gold < 0) {
            gold = -gold;
        }
        Map result = new HashMap();
        if (type == 3) {
            Map promoterTime = new HashMap();
            promoterTime.put(Integer.valueOf(userId), Long.valueOf(System.currentTimeMillis() + 120000L));
            com.miracle9.game.util.GameParameterAssist.bz.put(session, promoterTime);
            com.miracle9.game.util.GameParameterAssist.bB.put(Integer.valueOf(userId), Integer.valueOf(gold));
            if (com.miracle9.game.util.GameParameterAssist.bx.containsKey(Integer.valueOf(userId))) {
                AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity((IoSession) com.miracle9.game.util.GameParameterAssist.bx.get(Integer.valueOf(userId)), "showExpiryPwd", new Object[]{Integer.valueOf(gold)}));
            }
        } else {
            Map userTime = new HashMap();
            userTime.put(Integer.valueOf(userId), Long.valueOf(System.currentTimeMillis() + 120000L));
            com.miracle9.game.util.GameParameterAssist.bw.put(session, userTime);
            if (com.miracle9.game.util.GameParameterAssist.ba.containsKey(Integer.valueOf(userId))) {
                Map hallOut = new HashMap();
                hallOut.put("nType", Integer.valueOf(type));
                hallOut.put("nGameScore", Integer.valueOf(gold));
                AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity((IoSession) com.miracle9.game.util.GameParameterAssist.ba.get(Integer.valueOf(userId)), "inputPassword", new Object[]{hallOut}));
            }
        }
        result.put("success", Boolean.valueOf(true));
        result.put("message", "");
        return result;
    }

    public Map<String, Object> cancelGameInput(IoSession session) {
        Map result = new HashMap();
        int userId = 0;
        Map<Integer, Long> map = (Map) com.miracle9.game.util.GameParameterAssist.bw.get(session);
        if (map != null) {
            for (Map.Entry<Integer, Long> e : map.entrySet()) {
                userId = ((Integer) e.getKey()).intValue();
                IoSession s = (IoSession) com.miracle9.game.util.GameParameterAssist.ba.get(Integer.valueOf(userId));
                if (s != null) {
                    AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(s, "cancelWaitingExpiryUser", new Object[0]));
                }
            }
        }
        com.miracle9.game.util.GameParameterAssist.aI.remove(Integer.valueOf(userId));
        com.miracle9.game.util.GameParameterAssist.bw.remove(session);
        com.miracle9.game.util.GameParameterAssist.bz.remove(session);
        result.put("success", Boolean.valueOf(true));
        result.put("message", "");
        return result;
    }

    public void heart(IoSession session) {
        AmfMessageSend.storageMethodOperating.notifyAllOperating(new com.miracle9.game.server.message.StorageMethodEntity(session, "heart", new Object[0]));
    }

    public Admin getAdmin(int id) {
        return (Admin) this.adminServiceDao.getById(Integer.valueOf(id));
    }

    public boolean checkPromoterCode(String regCode) {
        try {
      /*if (this.ClassList == null)
      {
        this.ClassList = new com.miracle9.game.util.AuxiliaryCodingKey().ProcessDefineClass("com.miracle9.game.util.Register");
        this.object = this.ClassList.newInstance();
      }
      String serverIp = changeToIP(com.miracle9.game.util.GameParameterAssist.bK);
      Object result = this.ClassList.getDeclaredMethod("checkPromoterCode", new Class[] { String.class, String.class }).invoke(this.object, new Object[] { regCode, serverIp });
      return ((Boolean)result).booleanValue();*/
            return true;
        } catch (Exception e) {
            this.logger.error("", e);
        }
        return false;
    }

    public static String getAuthStr(Object language, int type) {
        String str = "";
        if (type == 0) {
            str = MyUtil.getProperties(language, "superAdmin");
        } else if (type == 1) {
            str = MyUtil.getProperties(language, "systemAdmin");
        } else if (type == 2) {
            str = MyUtil.getProperties(language, "zhuGuanAdmin");
        } else if (type == 3) {
            str = MyUtil.getProperties(language, "waiterAdmin");
        }
        return str;
    }

}
